﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class InviteNTFriendly : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = Resources.Resource.Default_PageTitle + ", " + Resources.Resource.InviteNTFriendly_PageTitle;
            OnlineUser ou = (OnlineUser)Session["User"];
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();

            if (ou.NationalTeamCoach == "0")
                Response.Redirect("~/TeamHomePage.aspx");

            string InvitedTeam = "";
            if (Request.QueryString["InvitedTeam"] != null)
                InvitedTeam = Request.QueryString["InvitedTeam"];
            else
                Response.Redirect("~/TeamHomePage.aspx");

            TeamIdHiddenField.Value = InvitedTeam;

            if (GND.ReadNivdalBoolData("Team1", "Team2", "Nivdal_CanTwoNTTeamsPlayFriendly", ou.NationalTeamCoach, InvitedTeam))
            {
                CannotInvitePanel.Visible = false;
                if (!IsPostBack)
                {
                    GameTimesSource.SelectParameters.Add("Team1", ou.NationalTeamCoach);
                    GameTimesSource.SelectParameters.Add("Team2", InvitedTeam);
                }

            }
        }

        protected void SendInvitation(object sender, EventArgs e)
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();

            string Answer = GND.ReadNivdalStringData("SuggestingUser", "ChalangedTeam", "Time", "SuggestingTeamHosts", "CupRules",
                "IsNationalTeams", "Nivdal_FriendlySuggestFriendly", ou.UserId, TeamIdHiddenField.Value, GameTimeDDL.SelectedValue,
                HomeAwayCheckBoxList.SelectedValue, CupRulesCheckBoxList.SelectedValue, "1");

            Response.Redirect("~/FriendlyNT.aspx?Message=" + Answer);

        }

        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }
    }
}